package com.tg.app.activity.device.add;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.appbase.custom.constant.CommonConstants;
import com.hjq.permissions.Permission;
import com.tg.app.R;
import com.base.BaseActivity;
import com.tg.app.report.DeviceAddReport;
import com.tg.app.report.DeviceAddReportBean;
import com.tg.app.util.LogUtils;
import com.tg.appcommon.android.PermissionUtil;
import com.tange.base.toolkit.PreferenceUtil;
import com.tg.appcommon.android.TGLog;


public class Add4GChooseActivity extends BaseActivity implements View.OnClickListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar  即隐藏标题栏
        setContentView(R.layout.activity_add_4g_choose);
        hideActionBar();
        initView();

        LogUtils.matTrackCustomKVEvent(this,"device_add","AD1");
        DeviceAddReportBean reportBean = new DeviceAddReportBean();
        reportBean.startTime = System.currentTimeMillis();
        reportBean.userID = String.valueOf(PreferenceUtil.getInt(this, CommonConstants.PRE_USER_ID));
        DeviceAddReport.getInstance().setReportBean(reportBean);


        // 目前只有4G行车记录仪选项，所以直接去下一级页面：
        Intent toQr = new Intent(this, Add4gCarDeviceActivity.class);
        startActivity(toQr);
        finish();
    }

    @Override
    public boolean shouldSetStatusBarColor() {
        return true;
    }

    @Override
    protected  void initView(){
        RelativeLayout add4g = findViewById(R.id.rel_add_4g);
        Button back = findViewById(R.id.add_choose_btn_back);
        add4g.setOnClickListener(this);
        back.setOnClickListener(this);

    }

    private final static String[] needQrcodeScanPermissions = {
            Permission.ACCESS_FINE_LOCATION,
            Permission.ACCESS_COARSE_LOCATION
    };

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] paramArrayOfInt) {
        super.onRequestPermissionsResult(requestCode, permissions, paramArrayOfInt);
        if (requestCode == AddFragmentTabActivity.PERMISSON_REQUESTCODE) {
            if (!PermissionUtil.verifyPermissions(paramArrayOfInt)) {      //没有授权
                TGLog.d("onRequestPermissionsResult = false");
            } else {
                TGLog.d("onRequestPermissionsResult = true");
            }
        }
    }

    private boolean requestPermission() {
        PermissionUtil permissionUtil = new PermissionUtil(Add4GChooseActivity.this);
        return permissionUtil.checkPermissions(Add4GChooseActivity.this, AddFragmentTabActivity.PERMISSON_REQUESTCODE, Add4GChooseActivity.needQrcodeScanPermissions);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override

    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.rel_add_4g) {
            Intent toQr = new Intent(this, Add4gCarDeviceActivity.class);
            startActivity(toQr);
        }  else if (id == R.id.add_choose_btn_back) {
            this.finish();
        }
    }
}
